'''
括号匹配问题:给一个字符串,其中包括小括号,中括号,大括号,求该字符串中的括号是否匹配
例如:
    ()()[]{}  匹配
    ([{()}])  匹配
    [](       不匹配
    [(])      不匹配
'''
class Stack:
    def __init__(self):
        self.stack = []
    def push(self,element):
        self.stack.append(element)
    def pop(self):
        return self.stack.pop()
    def get_top(self):
        if len(self.stack) > 0:
            return self.stack[-1]
        else:
            return None
    def is_empty(self):
        return len(self.stack)==0

# def pipei(string):
#     stack = Stack()
#     for i in string:
#         if stack == []:
#             stack.push(i)
#         elif stack != []:
#             if i == ')' and stack.get_top() == '(':
#                 stack.pop()
#             elif i == ']' and stack.get_top() == '[':
#                 stack.pop()
#             elif i == '}' and stack.get_top() == '{':
#                 stack.pop()
#
#     print(stack)
#
# print(pipei('()()[]{}'))
# print(pipei('([{()}])'))
# print(pipei('[]('))
# print(pipei('[(])'))


def pipei(string):
    # 修正：创建Stack实例（原代码漏了括号）
    stack = Stack()
    match = {'}':'{',']':'[',')':'('}
    for i in string:
        if i in '([{':
            # 左括号直接入栈
            stack.push(i)
        else:
            if stack.is_empty():
                return False
            elif stack.get_top() == match[i]:
                stack.pop()
            else:
                return False
    if stack.is_empty():
        return True
    else:
        return False


print(pipei('()()[]{}'))  # 应返回True
print(pipei('([)]'))  # 应返回False